package com.mall.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一结果数据返回类
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {
    private final static long serialVersionUID = 1L;
    //结果状态码
    private Integer code;

    //错误结果信息
    private String message;

    //结果数据
    private T data;

    public static <T> Result<T> success(T obj,String msg) {
        Result<T> r = new Result<>();
        r.code = Code.OK;
        r.data = obj;
        r.message = msg;
        return r;
    }

    public static <T> Result<T> error(Integer code, String msg){
        Result r = new Result();
        r.code = code;
        r.message = msg;
        return r;
    }
}
